version: '3'

services:
  ctfd:
    build: .
    user: root
    restart: always
    ports:
      - "8000:8000"
    environment:
      - UPLOAD_FOLDER=/var/uploads
      - DATABASE_URL=mysql+pymysql://ctfd:ctfd@db/ctfd
      - REDIS_URL=redis://cache:6379
      - WORKERS=1
      - LOG_FOLDER=/var/log/CTFd
      - ACCESS_LOG=-
      - ERROR_LOG=-
    volumes:
      - .data/CTFd/logs:/var/log/CTFd
      - .data/CTFd/uploads:/var/uploads
      - ./CTFd/plugins/ctfd-owl/source:/opt/CTFd/CTFd/plugins/ctfd-owl/source
      - .:/opt/CTFd:ro
      - /var/run/docker.sock:/var/run/docker.sock
      - /home/docker:/home/docker
      - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
    depends_on:
      - db
      - frpc
    networks:
        default:
        internal:
        frp_connect:

  db:
    image: mariadb:10.11
    restart: always
    environment:
      - MARIADB_ROOT_PASSWORD=ctfd
      - MARIADB_USER=ctfd
      - MARIADB_PASSWORD=ctfd
      - MARIADB_DATABASE=ctfd
      - MARIADB_AUTO_UPGRADE=1
    volumes:
      - .data/mysql:/var/lib/mysql
    networks:
        internal:
    # This command is required to set important mariadb defaults
    command: [mysqld, --character-set-server=utf8mb4, --collation-server=utf8mb4_unicode_ci, --wait_timeout=28800, --log-warnings=0,--max-connections=1000]

  cache:
    image: redis:4
    restart: always
    volumes:
    - .data/redis:/data
    networks:
        internal:

  frpc:
    image: shiraikuroko/frp:latest
    restart: always
    volumes:
      - ./conf/frp:/conf/
    entrypoint:
      - /usr/local/bin/frpc
      - -c
      - /conf/frpc.ini
    networks:
        default:
        frp_containers:
        frp_connect:
            ipv4_address: 172.1.0.4

  compose-frpc:
    image: shiraikuroko/frp:latest
    restart: always
    volumes:
      - ./conf/compose-frp:/conf/
    entrypoint:
      - /usr/local/bin/frpc
      - -c
      - /conf/frpc.ini
    networks:
      default:
      frp_containers:
      frp_connect:
        ipv4_address: 172.1.0.5

networks:
    default:
      ipam:
        config:
          - subnet: 172.4.0.0/16
    internal:
      internal: true
      ipam:
        config:
          - subnet: 172.3.0.0/16
    frp_connect:
        driver: overlay
        attachable: true
        internal: true

        ipam:
            config:
                - subnet: 172.1.0.0/16
    frp_containers:
        driver: overlay
        attachable: true
        ipam:
            config:
                - subnet: 172.2.0.0/16
